<?php

/*
	info: 用户注册
*/

require '../common.inc.php';

global_CheckPost(
	array(
		array('truename,','str','',$weblang['api_userTruenameError'],1),
		array('email,','email','',$weblang['api_userEmailError'],1),
		array('password','str','',$weblang['api_userPasswordError'],1),
		array('mobile,','str','',$weblang['api_userMobileError'],1),
		array('weddingdate','str','global_ConvTime(@)>0',$weblang['api_userWeddingdateError'],1),
));

if (!empty($webglobal['CPM']))
{
	$return['code'] = 1;
	$return['msg'] = reset($webglobal['CPM']);
	api_EchoReturn();
}

$webglobal['datainfo'] = $db->GetOne("SELECT * FROM user WHERE email='{$webglobal['CPP']['email']}' OR mobile='{$webglobal['CPP']['mobile']}'");
if (!empty($webglobal['datainfo']))
{
	if ($webglobal['datainfo']['email']==$webglobal['CPP']['email'])
	{
		$return['code'] = 2;
		$return['msg'] = $weblang['api_userEmailExists'];
		api_EchoReturn();
	}
	if ($webglobal['datainfo']['mobile']==$webglobal['CPP']['mobile'])
	{
		$return['code'] = 3;
		$return['msg'] = $weblang['api_userMobileExists'];
		api_EchoReturn();
	}
}

$webglobal['CPD']['password'] = md5($webglobal['CPP']['password']);
$webglobal['CPD']['weddingdate'] = global_ConvTime($webglobal['CPP']['weddingdate']);
$webglobal['CPD']['addtime'] = $webserver['timestamp'];
$tempaddid = $db->Insert('user', '', TRUE);
if (!$tempaddid)
{
	api_EchoReturn($weblang['api_databaseError']);
}

$return['code'] = 0;
$return['data']['member'] = array(
	'uid' => $tempaddid,
	'truename' => $webglobal['CPD']['truename'],
	'email' => $webglobal['CPD']['email'],
	'mobile' => $webglobal['CPD']['mobile'],
	'weddingdate' => global_FormatTime($webglobal['CPD']['weddingdate'], $webglobal['weddingdatemode']),
);
$objmem->SetUserCookie($webglobal['CPP']['email'], $webglobal['CPD']['password'], $webglobal['loginintime']);
api_EchoReturn();
